package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.AdditionalItemsAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.ztesoft.bss.common.util.ContextUtil;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * Description:主备冗余附加项属性联动处理类
 * File Name:AdditionalItemsAttrLinkHandler
 * Modification History:
 * Date             Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-7-14 16:18   邱萌         1.0       1.0 Version
 **/
@Service
@AttrHandler(AdditionalItemsAttrHandler.class)
public class AdditionalItemsAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        //获取省份标识
        String provinceCode = ContextUtil.getLoginInfo().getUserInfo().getPostProvinceNbr();
        //上海个性需求
        if (LocalKeyConsts.PROVINCE_SHANGHAI.equals(provinceCode)) {
            //主备冗余附加项
            if ("200003340".equals(attr.getFieldName())) {
                KiteAttr attachment = inst.getAttr("200003351");
                if (Objects.nonNull(attachment)) {
                    if ("100005786".equals(attr.getValue())) {
                        attachment.setShowType("D");
                        attachment.setIsNull(KeyConsts.IFTRUE_F);
                    } else {
                        attachment.setShowType("H");
                        attachment.setValue("");
                        attachment.setValueDesc("");
                        attachment.setIsNull(KeyConsts.IFTRUE_T);
                    }
                }
            }
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
